<template>
	<view class="my-config">
		<view class="config-item">
			<!-- <view class="lists" @tap="goPathList">
				<view class="con">地址管理</view>
				<image class="img-two" src="http://yunzhidun.oss-cn-beijing.aliyuncs.com/weixin/static/mine/Vector.png" mode="widthFix"></image>
			</view> -->
			<view class="lists"  @tap='updateNickname'>
				<view  class="con">修改昵称</view>
				<image class="img-two" src="http://yunzhidun.oss-cn-beijing.aliyuncs.com/weixin/static/mine/Vector.png" mode="widthFix"></image>
			</view>
			<view class="lists" @tap="toXieyi">
				<view  class="con">用户协议</view>
				<image class="img-two" src="http://yunzhidun.oss-cn-beijing.aliyuncs.com/weixin/static/mine/Vector.png" mode="widthFix"></image>
			</view>
		</view>
		<!-- <view class="my-exit" @tap='loginOut'>
			{{btnName}}
		</view> -->
		
		<view class="box" v-if="show"  @tap="coneal"></view>
		
		<view class="modal" v-if="show">
			<view class="title">
				修改昵称
			</view>
			<view class="content1">
				<input type="text" v-model="nickname">
			</view>
			<view class="btn-group">
				<view class="coneal" @tap="coneal">取消</view>
				<view class="submit" @tap="comfim">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickname:'',
				show:false,
				btnName:'退出登录'
			}
		},
		onLoad(options) {
			let userinfo = uni.getStorageSync('userinfo');
			
			if(!userinfo){
				this.btnName = '登录'
			}
			this.nickname = options.nickname
		},
		methods: {
			goPathList(){
				uni.navigateTo({
					url:('/pages/my-config/my-path-list')
				})
			},updateNickname(){
				this.show = true
			},
			comfim(){
				if(this.nickname == ''){
					uni.showToast({
						title:"名称不能为空",
						icon:"none"
					})
					return
				}
				
				let userinfo = uni.getStorageSync('userinfo')
				
				this.$api.interfaceApi('updateNickname')({
					'id':userinfo.id,
					'nickname':this.nickname
				}).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
					if(res.code == 1){
						this.show = false
					}
				})
			},
			coneal(){
				this.show = false
			},
			loginOut(){
				uni.setStorageSync('userinfo','');
				uni.navigateTo({
					url:'/pages/mine/login/register'
				})
			},
			toXieyi(){
				uni.navigateTo({
					url:'/pages/my-config/agreement'
				})
			},
		}
	}
</script>

<style scoped>
.my-config{
	background-color: #eff7ff;
	width: 100%;
	padding: 20rpx 0;
}
	
	.my-exit{
		background-color: #00aaff;
		line-height: 80rpx;
		margin: 12rpx 20rpx;
		color: #fff;
		border-radius: 20rpx;
		text-align: center;
	}
	
	.config-item{
		display: flex;
		flex-direction: column;
		
	}
		
		.lists{
			display: flex;
			padding: 10rpx;
			margin: 12rpx 20rpx;
			border-radius: 20rpx;
			height: 60rpx;
			border-right: 10rpx;
			background-color: #ffffff;
			justify-content: center;
			align-items: center;
			
		}
			.con{
				margin-left: 15rpx;
				width: 90%;
			}
			
			.img-two{
				width: 15rpx;
				margin-right: 30rpx;
			}
	
		.box{
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color:#000000;
			opacity: 0.5;
			z-index: 9998;
		}
		.modal{
			background-color: #FFFFFF;
			border-radius: 15rpx;
			width: 70%;
			height: 260rpx;
			position: absolute;
			top: 35%;
			left: 15%;
			z-index: 9999;
			padding: 20rpx;
			box-sizing: border-box;
			
			}
			.title{
				text-align: center;
				padding: 10rpx 0;
				font-size: 36rpx;
				box-sizing: border-box;
			}
			.content1{
				height: 70rpx;
				background-color: #f5f5f5;
				}
				.input{
					height: 70rpx;
					line-height: 70rpx;
					padding:  10rpx;
					box-sizing: border-box; 
				}
			
			.btn-group{
				display: flex;
				height: 80rpx;
				line-height: 80rpx;
				margin-top: 10rpx;
				}
				.coneal{
					width: 50%;
					text-align: center;
				}
				.submit{
					color: #007AFF;
					width: 50%;
					text-align: center;
				}
			
</style>
